/*
 * copy the DATA item from dslogic export file.
 * origin data like this:
 *
 * 658	0.633556	SETUP ADDR 1 EP 0
 * 659	0.633559	DATA0 [ 80 06 00 02 00 00 20 00 ]
 * 660	0.633568	ACK
 * 661	0.633572	IN ADDR 1 EP 0
 * 662	0.633576	NAK
 *
 */
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
	FILE *fp;
	char last[1024] = {0}, curr[1024] = {0};

	if(argc < 2) {
		fprintf(stderr, "Usage: sniffer filename\n");
		return -1;
	}

	fp = fopen(argv[1], "r");
	if (!fp) {
		fprintf(stderr, "can't open file: %s\n", argv[1]);
		return -1;
	}

	while (fgets(curr, sizeof(curr), fp)) {
		if (strstr(curr, "DATA")) {
			printf("%s", last); /* SETUP ADDR 1 EP 0 */
			printf("%s", curr); /* DATA0 [ 80 06 00 02 00 00 20 00 ] */
			fgets(curr, sizeof(curr), fp); /* ACK */
			printf("%s", curr);
		}
		strcpy(last, curr);
	}

	return 0;
}
